define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ad_log/index' + location.search,
                    add_url: 'ad_log/add',
                    edit_url: 'ad_log/edit',
                    del_url: 'ad_log/del',
                    multi_url: 'ad_log/multi',
                    import_url: 'ad_log/import',
                    table: 'ad_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'app_id', title: __('App_id')},
                        {field: 'come', title: __('Come'), searchList: {"0":__('Come 0'),"1":__('Come 1')}, formatter: Table.api.formatter.normal},
                        {field: 'adtype', title: __('Adtype'), searchList: {"0":__('Adtype 0'),"1":__('Adtype 1'),"2":__('Adtype 2'),"3":__('Adtype 3')}, formatter: Table.api.formatter.normal},
                        {field: 'node', title: __('Node'), searchList: {"0":__('Node 0'),"1":__('Node 1'),"2":__('Node 2'),"3":__('Node 3'),"4":__('Node 4')}, formatter: Table.api.formatter.normal},
                        {field: 'multiple', title: __('Multiple')},
                        {field: 'trigger', title: __('Trigger'), searchList: {"0":__('Trigger 0'),"1":__('Trigger 1')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'play', title: __('Play'), searchList: {"0":__('Play 0'),"1":__('Play 1')}, formatter: Table.api.formatter.normal},
                        {field: 'ext', title: __('Ext'), operate: 'LIKE'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'app.app_id', title: __('App.app_id'), operate: 'LIKE'},
                        {field: 'app.name', title: __('App.name'), operate: 'LIKE'},
                        {field: 'app.packagename', title: __('App.packagename'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});